/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.giant.entities;

import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author harold
 */
@Entity
@Table(name = "person")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),
    @NamedQuery(name = "Person.findByIdPerson", query = "SELECT p FROM Person p WHERE p.idPerson = :idPerson"),
    @NamedQuery(name = "Person.findByVatNumber", query = "SELECT p FROM Person p WHERE p.vatNumber = :vatNumber"),
    @NamedQuery(name = "Person.findByName", query = "SELECT p FROM Person p WHERE p.name = :name"),
    @NamedQuery(name = "Person.findByLastName", query = "SELECT p FROM Person p WHERE p.lastName = :lastName"),
    @NamedQuery(name = "Person.findByCorpName", query = "SELECT p FROM Person p WHERE p.corpName = :corpName"),
    @NamedQuery(name = "Person.findByEmail", query = "SELECT p FROM Person p WHERE p.email = :email"),
    @NamedQuery(name = "Person.findByStatus", query = "SELECT p FROM Person p WHERE p.status = :status")})
public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_person")
    private Integer idPerson;
    @Column(name = "vat_number")
    private BigInteger vatNumber;
    @Size(max = 100)
    @Column(name = "vat_office")
    private String vatOffice;
    @Column(name = "commercial_registration")
    private Integer commercialRegistration;
    @Size(max = 500)
    @Column(name = "name")
    private String name;
    @Size(max = 500)
    @Column(name = "last_name")
    private String lastName;
    @Size(max = 256)
    @Column(name = "corp_name")
    private String corpName;
    @Size(max = 500)
    @Column(name = "address")
    private String address;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Size(max = 50)
    @Column(name = "email")
    private String email;
    @Size(max = 50)
    @Column(name = "telephone")
    private String telephone;
    @Size(max = 50)
    @Column(name = "mobile")
    private String mobile;
    @Basic(optional = false)
    @NotNull
    @Column(name = "status")
    private boolean status;
    @OneToOne
    @JoinColumn(name = "id_type_nature")
    private TypeNature idTypeNature;
    @Basic(optional = false)
    @NotNull
    @Column(name = "dealer")
    private boolean dealer;
    @OneToOne
    @JoinColumn(name = "id_type_dealer")
    private TypeDealer idTypeDealer;

    public Person() {
    }

    public Person(Integer idPerson) {
        this.idPerson = idPerson;
    }

    public Person(Integer idPerson, boolean status) {
        this.idPerson = idPerson;
        this.status = status;
    }

    public Integer getIdPerson() {
        return idPerson;
    }

    public void setIdPerson(Integer idPerson) {
        this.idPerson = idPerson;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getCorpName() {
        return corpName;
    }

    public void setCorpName(String corpName) {
        this.corpName = corpName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public boolean getStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public TypeNature getIdTypeNature() {
        return idTypeNature;
    }

    public void setIdTypeNature(TypeNature idTypeNature) {
        this.idTypeNature = idTypeNature;
    }

    public BigInteger getVatNumber() {
        return vatNumber;
    }

    public void setVatNumber(BigInteger vatNumber) {
        this.vatNumber = vatNumber;
    }

    public String getVatOffice() {
        return vatOffice;
    }

    public void setVatOffice(String vatOffice) {
        this.vatOffice = vatOffice;
    }

    public Integer getCommercialRegistration() {
        return commercialRegistration;
    }

    public void setCommercialRegistration(Integer commercialRegistration) {
        this.commercialRegistration = commercialRegistration;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public boolean getDealer() {
        return dealer;
    }

    public void setDealer(boolean dealer) {
        this.dealer = dealer;
    }

    public TypeDealer getIdTypeDealer() {
        return idTypeDealer;
    }

    
    public void setIdTypeDealer(TypeDealer idTypeDealer) {
        this.idTypeDealer = idTypeDealer;
    }
    
    public String getFullName()
    {
        String fullName="";
        //Natural Person
        if(idTypeNature.getIdTypeNature()==1)
        {
            fullName=getName()+" "+getLastName();
        }
        //Corporate person
        else{
            fullName=getCorpName();
        }
        return fullName;
            
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPerson != null ? idPerson.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.idPerson == null && other.idPerson != null) || (this.idPerson != null && !this.idPerson.equals(other.idPerson))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.giant.entities.Person[ idPerson=" + idPerson + " ]";
    }
    
}
